package com.onlinemart.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.onlinemart.controller.ConnectionFactory;

public class Buisness   {
	private Connection connection;
	public Buisness()
	{
		connection=ConnectionFactory.getConnection();
	}
	
	public boolean validateUser(String emailId, String passwd)
	{
		System.out.println("In Buisness validateUser");
		try
		{
			String rsMailId=null;
			String rsPasswd=null;
			PreparedStatement preparedStatement = connection.prepareStatement("select username, password from user where password=?");
			preparedStatement.setString(1, passwd);
			ResultSet resultSet = preparedStatement.executeQuery();
			while(resultSet.next())
			{
				rsMailId = resultSet.getString("username");
				System.out.println("Username is taken from database");
				rsPasswd = resultSet.getString("password");
			}
			System.out.println(rsPasswd);
			if(rsMailId.equalsIgnoreCase(emailId) && rsPasswd.equalsIgnoreCase(passwd))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return false;
		}
	}
	
	//private 
}
